package openase.audiosearch.comm.request.encoder;

import java.nio.ByteBuffer;

import openase.audiosearch.comm.request.AudioSearch;
import openase.audiosearch.comm.request.RequestType;


public class AudioSearchRequestEncoder implements RequestEncoder<AudioSearch> {

	public ByteBuffer encode(AudioSearch request) {
		byte[] audio = request.getAudioInput();
		int maxResults = request.getMaxResults();

		ByteBuffer buffer = ByteBuffer.allocate(1 + 4 + audio.length + 4);
		buffer.put(RequestType.SEARCH.getId());
		buffer.putInt(audio.length);
		buffer.put(audio);
		buffer.putInt(maxResults);

		return buffer;
	}
}
